package zjz.graduation.backend.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import zjz.graduation.backend.mapper.AdminsDao;
import zjz.graduation.backend.model.Admins;

import java.util.List;

@Service
public class AdminsServiceImpl implements AdminsService {
    @Autowired
    AdminsDao adminsDao;

    @Override
    public boolean isExist(int uid) {
        return adminsDao.selectByUid(uid)!=null;
    }
    
    @Override
    public List<Admins> getAdmins() {
    	return adminsDao.getAdmins();
    }

    @Override
    public void updateRole(int uid, int role) {
        Admins admins = new Admins(uid);
        // 如果更新为管理员
        if(role==1){
            adminsDao.insert(admins);
        }
        // 如果更新为普通用户
        else{
            adminsDao.deleteByUid(uid);
        }
    }
}
